package com.study.mike.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.study.mike.model.po.FishEqPO;
import com.study.mike.model.po.FishEquipmentPO;
import com.study.mike.result.R;
import com.study.mike.result.RUtil;
import com.study.mike.service.FishEquipmentService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author KangHui
 * @Date 2023/6/20 15:48
 */
@RestController
@RequestMapping("equipment")
public class FishEquipmentController {
    @Resource
    private FishEquipmentService fishEquipmentService;


    /**
     * 新增数据
     *
     * @param po
     * @return
     */
    @PostMapping("/add")
    public R addFishEq(@RequestBody FishEquipmentPO po) {
        if (StrUtil.isBlank(po.getName())) {
            return RUtil.fail("名称不能为空");
        }
        if (StrUtil.isBlank(po.getBn())) {
            return RUtil.fail("编码不能为空");
        }
        return RUtil.success(fishEquipmentService.addFishEq(po));
    }

    /**
     * 编辑数据
     *
     * @param po
     * @return
     */
    @PostMapping("update")
    public R updateFishEq(@RequestBody FishEquipmentPO po) {
        if (ObjectUtil.isNull(po.getId())) {
            return RUtil.fail("操作数不能为空");
        }
        Boolean flag = fishEquipmentService.updateFishEq(po);
        if (flag) {
            return RUtil.success("操作成功");
        }
        return RUtil.fail("操作失败");
    }

    /**
     * 设置状态
     *
     * @param po
     * @return
     */
    @PostMapping("setStatus")
    public R setStatus(@RequestBody FishEquipmentPO po) {
        if (ObjectUtil.isNull(po.getId())) {
            return RUtil.fail("操作数不能为空");
        }
        return RUtil.success(fishEquipmentService.setStatus(po.getId(), po.getStatus()));
    }


    /**
     * 分页查询
     *
     * @param po
     * @return
     */
    @PostMapping("query")
    public R queryFishEq(@RequestBody FishEqPO po) {
        return RUtil.success(fishEquipmentService.queryFishEq(po));
    }

    /**
     * 删除
     *
     * @param pos
     * @return
     */
    @PostMapping("deleteBatch")
    public R deleteFishEq(@RequestBody List<FishEquipmentPO> pos) {
        return RUtil.success(fishEquipmentService.deleteFishEq(pos));
    }

}
